package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.exceptionDataPojo;
import com.example.pojo.problemDataPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:WorkExceptionRemovalMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2025/3/3 18:07
 * @Version 1.0
 */
@Mapper
public interface WorkExceptionRemovalMapp {
    //电脑端插入一行报警\异常解除的信息
    @DS("newMscLowCodeFormal")
    @Insert("insert into exception_data " +
            "(establishTime, updateTime, deleteSign, " +
            "editName, workShop, lineName, " +
            "op, excMessage, excDate, " +
            "excPersonName, excType,isProblem," +
            "downTimeOp,downTimeLine) VALUES (" +
            "#{establishTime},#{updateTime},#{deleteSign}," +
            "#{editName},#{workShop},#{lineName}," +
            "#{op},#{excMessage},#{excDate}," +
            "#{excPersonName},#{excType},#{isProblem}," +
            "#{downTimeOp},#{downTimeLine})")
    void excInsertOne(exceptionDataPojo exceptionDataPojo);
    //把所有的数据查出来，再反馈给前端
    @DS("newMscLowCodeFormal")
    @Select("select * from exception_data where deleteSign=1")
    List<exceptionDataPojo> inquiryAll();
    //向问题数据库插入一条数据
    @DS("newMscLowCodeFormal")
    @Insert("insert into problem_data " +
            "(establishTime, updateTime, deleteSign, " +
            "editName, workshop, lineName, " +
            "drawing, op, occurDate, " +
            "noteTaker, liability, liabilityNub, " +
            "problemName, describeUse, describeAnnex, " +
            "quantity, introspection, statusUse, " +
            "origin, outflow, temporaryUse, " +
            "correct, switchDate, switchNumber, " +
            "correctDate, temporaryDate, temporaryLiability, " +
            "permanentDate, permanentLiability, introspectionDate, " +
            "introspectionLiability, conclusion, finish, " +
            "report, type1, correctOut, " +
            "type2, machinePlateName, machinePlateId, " +
            "peoplePlateName, peoplePlateId, materialPlateName, " +
            "materialPlateId, methodPlateName, methodPlateId, " +
            "environmentPlateName, environmentPlateId, " +
            "measurePlateName, measurePlateId,writeName," +
            "examineName,approveName,liabilityName," +
            "isIndemnify,isEndIndemnify,supplierName," +
            "isExam,saleDate,mileage,serviceId,partName) " +
            "VALUES (" +
            "#{establishTime}, #{updateTime}, #{deleteSign}, " +
            "#{editName}, #{workshop}, #{lineName}, " +
            "#{drawing}, #{op}, #{occurDate}, " +
            "#{noteTaker}, #{liability}, #{liabilityNub}, " +
            "#{problemName}, #{describeUse}, #{describeAnnex}, " +
            "#{quantity}, #{introspection}, #{statusUse}, " +
            "#{origin}, #{outflow}, #{temporaryUse}, " +
            "#{correct}, #{switchDate}, #{switchNumber}, " +
            "#{correctDate}, #{temporaryDate}, #{temporaryLiability}, " +
            "#{permanentDate}, #{permanentLiability}, #{introspectionDate}, " +
            "#{introspectionLiability}, #{conclusion}, #{finish}, " +
            "#{report}, #{type1}, #{correctOut}, " +
            "#{type2}, #{machinePlateName}, #{machinePlateId}, " +
            "#{peoplePlateName}, #{peoplePlateId}, #{materialPlateName}, " +
            "#{materialPlateId}, #{methodPlateName}, #{methodPlateId}, " +
            "#{environmentPlateName}, #{environmentPlateId}, " +
            "#{measurePlateName}, #{measurePlateId},#{writeName}," +
            "#{examineName},#{approveName},#{liabilityName}," +
            "#{isIndemnify},#{isEndIndemnify},#{supplierName}," +
            "#{isExam},#{saleDate},#{mileage},#{serviceId},#{partName})")
    void problemInserOne(problemDataPojo problemDataPojo);
    //数据赋值，向后端筛选是“机”的所有问题，需要的是一个根据一个字段进行筛选
    @DS("newMscLowCodeFormal")
    @Select("select * from problem_data where deleteSign=1 and ${firstFiledName}=#{firstFiledVal}")
    List<problemDataPojo> inquiryProblemOneFiled(String firstFiledName, String firstFiledVal);
    //辅助函数：对报警/异常问题库的一个行的某一个字段进行修改,修改的值是数字
    @DS("newMscLowCodeFormal")
    @Update("update exception_data set ${firstFiledName}=#{firstFiledVal} where id=#{id}")
    void editOneFiledExceptionDataInt(Integer id, String firstFiledName, int firstFiledVal);
    //辅助函数：对问题库，修改一个字段，是字符串
    @DS("newMscLowCodeFormal")
    @Update("update problem_data set ${filedName}=#{filedVal} where id=#{id}")
    void editOneFiledStr(String filedName, String filedVal, Integer id);
    //辅助函数：对问题库，修改一个字段，是数字
    @DS("newMscLowCodeFormal")
    @Update("update problem_data set ${filedName}=#{filedVal} where id=#{id}")
    void editOneFiledInt(String filedName, int filedVal, Integer id);
    //根据ID，修改一行报警数据,所有的字段都修改
    @DS("newMscLowCodeFormal")
    @Update("UPDATE exception_data SET " +
            "establishTime = #{establishTime}, " +
            "updateTime = #{updateTime}, " +
            "deleteSign = #{deleteSign}, " +
            "editName = #{editName}, " +
            "workShop = #{workShop}, " +
            "lineName = #{lineName}, " +
            "op = #{op}, " +
            "excMessage = #{excMessage}, " +
            "excPersonName = #{excPersonName}, " +
            "excType = #{excType}, " +
            "isProblem = #{isProblem}, " +
            "downTimeOp = #{downTimeOp}, " +
            "downTimeLine = #{downTimeLine}, " +
            "create_time = #{create_time}, " +    // 保持下划线命名
            "update_time = #{update_time}, " +    // 保持下划线命名
            "creator = #{creator}, " +
            "process_status = #{process_status}, " + // 保持下划线命名
            "sys_update_user = #{sys_update_user}, " + // 保持下划线命名
            "sys_audit_user = #{sys_audit_user}, " +
            "sys_audit_time = #{sys_audit_time}, " +
            "sys_deleted = #{sys_deleted}, " +
            "excDate = #{excDate}, " +
            "liftName = #{liftName}," +
            "isProductionOk=#{isProductionOk}," +
            "restorationType=#{restorationType} " +
            "WHERE id = #{id}")
    void excEditOne(exceptionDataPojo pojo);
    //辅助函数：对报警/ 异常信息表中，对一个日期类型的数据，筛选≥某一个值，和＜某一个值
    @DS("newMscLowCodeFormal")
    @Select("select * from exception_data where ${filedName}>=#{minVal} and ${filedName}<#{maxVal} ORDER BY ${filedName} DESC")
    List<exceptionDataPojo> queryExceptionOneFiledScope(String filedName, LocalDateTime minVal, LocalDateTime maxVal);
}
